package cn.edu.scau.cmi.huangzhiyuan.client;

import cn.edu.scau.cmi.huangzhiyuan.abstractFactory.domainAbstractClass.Insurance;
import cn.edu.scau.cmi.huangzhiyuan.abstractFactory.factory.AbstractFactory;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class AbstractFactoryClient extends Application {
	public TextArea introduction = new TextArea("选择对应保险，展示相关信息");
	public Insurance insurance = null;

	@Override
	public void start(Stage primaryStage) throws Exception {
		try {
			BorderPane pane = new BorderPane();

			// 放置头像
			Image image = new Image("file:src/main/resources/img/avatar.jpg");
			ImageView imageView = new ImageView(image);
			imageView.setFitWidth(260);
			imageView.setFitHeight(230);
			pane.setLeft(imageView);

			GridPane centerPane = new GridPane();
			centerPane.setPadding(new Insets(20));
			// 构造选项
			ChoiceBox<String> cb = new ChoiceBox<String>();
			cb.setItems(FXCollections.observableArrayList("PICC驾驶员保险", "PICC汽车保险", "PICC伤亡保险", "PICC其它事故保险",
					"PingAn驾驶员保险", "PingAn汽车保险", "PingAn伤亡保险", "PingAn其它事故保险"));

			// 设置默认选项
//			cb.getSelectionModel().select(0);

			// 设置下拉框监听器
			cb.setOnAction(event -> {
				switch (cb.getSelectionModel().getSelectedIndex()) {
				case 0:
					insurance = AbstractFactory.getFactory("PICC").BodyInsurance();
					break;
				case 1:
					insurance = AbstractFactory.getFactory("PICC").CarInsurance();
					break;
				case 2:
					insurance = AbstractFactory.getFactory("PICC").PersonInsurance();
					break;
				case 3:
					insurance = AbstractFactory.getFactory("PICC").OtherInsurance();
					break;
				case 4:
					insurance = AbstractFactory.getFactory("PingAn").BodyInsurance();
					break;
				case 5:
					insurance = AbstractFactory.getFactory("PingAn").CarInsurance();
					break;
				case 6:
					insurance = AbstractFactory.getFactory("PingAn").PersonInsurance();
					break;
				case 7:
					insurance = AbstractFactory.getFactory("PingAn").OtherInsurance();
					break;
				}
				introduction.setText(insurance.information());
			});

			// 设置个人信息
			Label stnLabel = new Label("学号： 2016207010408");
			Label nameLabel = new Label("姓名：  黄智源");
			stnLabel.setPadding(new Insets(10));
			nameLabel.setPadding(new Insets(10));
			centerPane.add(nameLabel, 0, 0);
			centerPane.add(stnLabel, 1, 0);

			// 设置下拉菜单
			centerPane.add(cb, 0, 1);

			// 放到中间面版
			pane.setCenter(centerPane);

			// 放置操作提示到底部
			introduction.prefHeight(200);
			introduction.setEditable(false);
			pane.setBottom(introduction);

			// 设置面板
			Scene scene = new Scene(pane, 600, 400);

			// 放置面板
			primaryStage.setScene(scene);

			// 设置窗口标题
			primaryStage.setTitle("实验三：抽象工厂模式");

			// 展示
			primaryStage.show();
		} catch (Exception e) {
			System.out.println(e);
		}
	}

	public static void main(String[] args) {
		launch(args);
	}
}
